<template>

        <h2>添加信息</h2>

        <table class="table table-bordered  " >
                <tr>
                        <th>卷类型</th>
                        <th>
                                <select v-model="Tianjia1.juanType">
                                        <option value="卷类型">卷类型</option>
                                        <option value="代金卷">代金卷</option>
                                        <option value="补偿卷">补偿卷</option>
                                </select>
                        </th>

                </tr>


                <tr>
                        <th>代金卷标题</th>
                        <th>
                                <input type="text" v-model="Tianjia1.mname">
                        </th>

                </tr>


                <tr>
                        <th>代金卷副标题</th>
                        <th>
                                <input type="text" v-model="Tianjia1.mtname">
                        </th>

                </tr>


                <tr>
                        <th>代金卷图片</th>
                        <th>
                                <img :src="Tianjia1.mimg" style="width: 80px; height:100px;">
                                <input type="file" @change="Upfile">
                        </th>

                </tr>


                <tr>
                        <th>剩余库存</th>
                        <th>
                                <input type="text" v-model="Tianjia1.mnum">
                        </th>

                </tr>




                <tr>
                        <th>使用条件</th>
                        <th>
                                <input type="text" v-model="Tianjia1.tiaoJian">
                        </th>

                </tr>


           


                <tr>
                        <th>有效期</th>
                        <th>
                                <input type="date" v-model="Tianjia1.ctime">
                                <input type="date" v-model="Tianjia1.stime">
                        </th>

                </tr>


                <tr>
                        <th>适用业务</th>
                        <th>
                                <input type="checkbox" value="订房" :checked="XuanZe" v-model="DuoXuan"> 订房
                                <input type="checkbox" value="商城" :checked="XuanZe" v-model="DuoXuan"> 商城
                                <input type="checkbox" value="堂食" :checked="XuanZe" v-model="DuoXuan"> 堂食
                                <input type="checkbox" value="收款码" :checked="XuanZe" v-model="DuoXuan"> 收款码
                        </th>

                </tr>


                <tr>
                        <th>使用须知</th>
                        <th>
                                <textarea v-model="Tianjia1.xuZhi"></textarea>
                        </th>

                </tr>



                <tr>
                        <th>适用门店</th>
                        <th>
                                <select v-model="Tianjia1.tid" @change="Jianmian1">
                                        <option :value="-1">请选择</option>
                                        <option v-for="item in FanTian" :value="item.tid">{{ item.tname }}</option>
                                </select>
                        </th>

                </tr>


                <tr >
                        <th>服务电话</th>
                        <th>
                                <input type="text" v-model="Tianjia1.mPhone" >
                        </th>

                </tr>

                <tr   v-if="Tianjia1.tid!=-1">
                        <th>减免金额</th>
                        <th >
                            <input         v-model="Tianjia1.jianMian"         readonly="true" >
                       
                       
                        </th>

                </tr>

                <tr>
                        <th></th>
                        <th>
                                <button value="添加" @click="AddMe" class="btn btn-success">添加</button>
                        </th>

                </tr>


        </table>



</template>

<script setup lang="ts">





const DuoXuan = ref([])
const XuanZe = ref(false)



const Jianmian1=()=>{


                 if(Tianjia1.value.tid==1)
                {
                Tianjia1.value.jianMian=2000
                }
                else if(Tianjia1.value.tid==2)
                {
                        Tianjia1.value.jianMian=3000 
                }
                else if(Tianjia1.value.tid==3)
                {
                        Tianjia1.value.jianMian=4000 
                }
                else if(Tianjia1.value.tid==-1)
                {
                        Tianjia1.value.jianMian=0  
                }


}






import axios from 'axios';
import { onMounted, ref } from 'vue';

const Upfile = (e: any) => {

        var a = e.target.files[0];
        var b = new FormData()
        b.append("Images", a);

        axios.post('https://localhost:7039/api/UpFile/UpFi', b).then(res => {


                Tianjia1.value.mimg = res.data





        })

}



const FanTian = ref([{

        "tid": 0,
        "tname": ""

}])


onMounted(() => {

        FanTian1();
   
})



const FanTian1 = () => {


        axios.get('https://localhost:7039/api/User/ShowType').then(res => {

                FanTian.value = res.data

        })

}






const Tianjia1 = ref({


        "mname": "",
        "mtname": "",
        "mimg": "",
        "mnum": 0,
        "tiaoJian": 0,
        "jianMian": 0,
        "ctime": "",
        "stime": "",
        yeWu: "",
        "xuZhi": "",
        "juanType": "卷类型",
        "mPhone": "",
        "tid": -1,
        "isDel": true


})






const AddMe = () => {

       



        Tianjia1.value.yeWu=DuoXuan.value.toString();

        
        axios.post('https://localhost:7039/api/User/AddMark', Tianjia1.value).then(res => {



                if (res.data > 0) {

                  
                        alert('添加成功')
                }
                else {
                        alert('添加失败')
                }
        })



}



</script>